package com.ktgj.pay.payUtil;

import com.alipay.api.domain.BankCardInfo;
import com.epos.facade.EposFacade;
import com.epos.util.Configuration;
import com.ktgj.customer.api.RemoteCustomerService;
import com.ktgj.customer.api.domain.BankCard;
import com.ktgj.customer.api.domain.Customer;
import com.ktgj.pay.YeeBaoPay.YeeBaoResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Component
public class YeeBaoPayUtil {
    private String JSJ_CODE_YES = "10012434762";//（需要验证码）
    private String JSJ_KEY_YES = "b4rT631521oQ85Go1L92q5110XUlXYV72ZK6z4xD101VZ91C2ok38X725Q1U";

    private String JSJ_CODE = "10012464064";//（只有第一次需要验证码）
    private String JSJ_KEY = "yARBp2R538472l823F35T440FR00rI1uG19he1JRI7XZV63PqZK79z143po0";

    private String JSJ_CODE_NO = "10011888556";//（不需要验证码）
    private String JSJ_KEY_NO = "9324Kcqk0W4fIM9o216pK7kn4qf582c657o6mQ1db13GQwI6oIo1x202165P";


    private String URL = "127.0.0.1";

    /**
     * 信用卡消费
     *
     * @param bankCard
     * @return
     */
    public YeeBaoResult CreditSale(String jsjOrderId, String moneyAmout, Customer customer, BankCard bankCard, String callBackUrl, String payType) {
        String p0_Cmd = "EposSale";//业务类型:(固定值“EposSale”)
        String p2_Order = jsjOrderId;//"test001";//商户订单号
        String p3_Amt=moneyAmout;//消费金额:(最小值为 0.1 元)
        String p4_Cur="CNY";//交易币种:(固定值 “CNY”)
        String p5_Pid="JSJ_GOODS";//商品名称:(此参数如用到中文,请注意转码)
        String p8_Url=URL;//接收支付结果地址:(用 request 接收结果,如该地址设置 为localhost 或127.0.0.1将收不到交易结果返回)
        String pa_CredType="IDCARD";//证件类型
        String pr_NeedResponse="1";//需要应答:(固定值“1”)
        String prisk_Param = "";
        Map<String,String> hm= new HashMap<>();
        hm.put("p0_Cmd",p0_Cmd);////业务类型
        hm.put("p2_Order",p2_Order);//商户订单号
        hm.put("p3_Amt",p3_Amt);//消费金额
        hm.put("p4_Cur",p4_Cur);//交易币种
        hm.put("p5_Pid",p5_Pid);//商品名称
        hm.put("p8_Url",p8_Url);//接收支付结果地址
        hm.put("pa_CredType",pa_CredType);//证件类型
        hm.put("pb_CredCode",customer.getCustCertificateNo());//证件号码
        hm.put("pd_FrpId",bankCard.bankCode);//银行编码
        hm.put("pe_BuyerTel",customer.getContractPhoneOne());//消费者手机号
        hm.put("pf_BuyerName",bankCard.getCardholder());//消费者姓名
        hm.put("pt_ActId",bankCard.getCardNumber());//信用卡卡号
        hm.put("pa2_ExpireYear",bankCard.getCreditCardTime().substring(0, 4));//有效期（年）
        hm.put("pa3_ExpireMonth",bankCard.getCreditCardTime().substring(5, 7));//有效期（月）
        hm.put("pa4_CVV",bankCard.getCvv2().toString());//CVV
        hm.put("pe_IsBind","1");//是否绑卡
        hm.put("pe_Identitytype","3");//用户标识
        hm.put("pe_Identityid","userId456");//标识数据
        hm.put("prisk_Param", prisk_Param);//风控扩展参数
        hm.put("pr_NeedResponse",pr_NeedResponse);//需要应答
        String hmacKey;
        if (payType.equals("Crm")){
            hmacKey = this.JSJ_KEY_NO;//签名数据
        }
        else {
            hmacKey = this.JSJ_KEY_YES;//签名数据
        }
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            if (payType == null){
                payType = "App";
            }
            if (payType.equals("Crm")){
                result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_NO,hmacKey,hm, "POST", "gbk");
            }
            else {
                result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_YES,hmacKey,hm, "POST", "gbk");
            }
            yeeBaoResult.setBankOrderId(result.get("ro_BankOrderId")==null?"":result.get("ro_BankOrderId"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setErrorMsg(result.get("errorMsg")==null?"":result.get("errorMsg"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            yeeBaoResult.setOrder(result.get("r6_Order")==null?"":result.get("r6_Order"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口交易异常");
        }
        return yeeBaoResult;
    }

    /**
     * 信用卡退款
     *
     * @return
     */
    public YeeBaoResult CreditRefund(String jsjOrderId, String yeeBaoTrxId, String moneyAmout, String payType)
    {
        String p0_Cmd = "RefundOrd";//业务类型:(固定值 “RefundOrd”)
        String p2_Order = jsjOrderId;//"test001";//商品订单号
        String pb_TrxId = yeeBaoTrxId;//易宝支付交易流水号:(易宝支付平台产生的交易流水号，每笔订单 唯一)
        String p3_Amt = moneyAmout;//退款金额
        String p4_Cur="CNY";//交易币种:(不填或填固定值 ”CNY”)
        String p5_Desc = "买错商品";//退款说明:(此参数如用到中文，请注意转码)

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);////业务类型
        hm.put("p2_Order",p2_Order);//退款请求号(商品订单号)
        hm.put("pb_TrxId",pb_TrxId);//易宝支付交易流水号
        hm.put("p3_Amt",p3_Amt);//退款金额
        hm.put("p4_Cur",p4_Cur);//交易币种
        hm.put("p5_Desc",p5_Desc);//退款说明

        String hmacKey;
        if (payType.equals("Crm")){
            hmacKey = this.JSJ_KEY_NO;//签名数据
        }
        else {
            hmacKey = this.JSJ_KEY_YES;//签名数据
        }
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;

            if (payType.equals("Crm")){
                result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_NO,hmacKey,hm, "POST", "gbk");
            }
            else {
                result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_YES,hmacKey,hm, "POST", "gbk");
            }
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            yeeBaoResult.setOrder(result.get("r4_Order")==null?"":result.get("r4_Order"));
            yeeBaoResult.setAmt(result.get("r3_Amt")==null?"":result.get("r3_Amt"));
            yeeBaoResult.setFee(result.get("rf_fee")==null?"":result.get("rf_fee"));
            yeeBaoResult.setCur(result.get("r4_Cur")==null?"":result.get("r4_Cur"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口退款异常");
        }
        return yeeBaoResult;
    }

    /**
     * 借记卡消费
     * @return
     */
    public YeeBaoResult DebitSale(String jsjOrderId, String moneyAmout, Customer customer, BankCard bankCard, String callBackUrl)
    {
        String p0_Cmd = "EposDebitSaleNew";//业务类型:(固定值“EposDebitSaleNew”)
        String p2_Order = jsjOrderId;//商户交易号
        String p3_Amt = moneyAmout;//交易金额:(最小值为0.1元)
        String p4_Cur = "CNY";//交易币种:(固定值“CNY”)
        String p5_Pid = "JSJ_GOODS";//商品名称:(此参数如用到中文，请注意转码)
        String p8_Url = URL;//回调地址:(用 request 接收结果,如该地址设置 为localhost 或127.0.0.1将收不到交易结果返回)
        String pa_CredType = "IDCARD";//证件类型:(身份证：IDCARD)
        String pr_NeedResponse="1";//需要应答:(固定值“1”)

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);//业务类型
        hm.put("p2_Order",p2_Order);//商户交易号
        hm.put("p3_Amt",p3_Amt);//交易金额
        hm.put("p4_Cur",p4_Cur);//交易币种
        hm.put("p5_Pid",p5_Pid);//商品名称
        hm.put("p8_Url",p8_Url);//回调地址
        hm.put("pa_CredType",pa_CredType);//证件类型
        hm.put("pb_CredCode",customer.getCustCertificateNo());//证件号码
        hm.put("pe_BuyerTel",customer.getContractPhoneOne());//手机号
        hm.put("pf_BuyerName",bankCard.getCardholder());//消费者姓名
        hm.put("pt_ActId",bankCard.getCardNumber());//账号
        hm.put("pr_NeedResponse",pr_NeedResponse);//需要应答

        String hmacKey = this.JSJ_KEY_NO;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_NO,hmacKey,hm, "POST", "gbk");
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setErrorMsg(result.get("errorMsg")==null?"":result.get("errorMsg"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            yeeBaoResult.setAmt(result.get("r3_Amt")==null?"":result.get("r3_Amt"));
            yeeBaoResult.setCur(result.get("r4_Cur")==null?"":result.get("r4_Cur"));
            yeeBaoResult.setOrder(result.get("r6_Order")==null?"":result.get("r6_Order"));
            yeeBaoResult.setBankOrderId(result.get("ro_BankOrderId")==null?"":result.get("ro_BankOrderId"));
            yeeBaoResult.setbType(result.get("r7_BType")==null?"":result.get("r7_BType"));
            yeeBaoResult.setSystemsSign(result.get("r_SystemsSign")==null?"":result.get("r_SystemsSign"));
            yeeBaoResult.setSystemsCustomerSign(result.get("r_SystemsCustomerSign")==null?"":result.get("r_SystemsCustomerSign"));
            yeeBaoResult.setPayDate(result.get("rp_PayDate")==null?"":result.get("rp_PayDate"));
            yeeBaoResult.setTrxtime(result.get("ru_Trxtime")==null?"":result.get("ru_Trxtime"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口交易异常");
        }
        return yeeBaoResult;
    }

    /**
     * 借记卡退款
     * @param 
     * @return
     */
    public YeeBaoResult DebitRefund(String jsjOrderId, String yeeBaoTrxId, String moneyAmout)
    {
        String p0_Cmd = "EposDebitRefundNew";
        String p2_Order = jsjOrderId;//退款请求号
        String pb_TrxId = yeeBaoTrxId;//易宝支付交易流水号
        String p3_Amt = moneyAmout;//消费金额
        String p4_Cur = "CNY";//交易币种
        String p5_Desc = "";//退款备注
        String pv_Ver = "";//版本号
        String ps_ProvinceCode = "";//收款行省份编码
        String pt_ResourceCode = "";//收款行城市编码
        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);
        hm.put("p2_Order",p2_Order);
        hm.put("pb_TrxId",pb_TrxId);
        hm.put("p3_Amt",p3_Amt);
        hm.put("p4_Cur",p4_Cur);
        hm.put("p5_Desc",p5_Desc);
        hm.put("pv_Ver",pv_Ver);
        hm.put("ps_ProvinceCode",ps_ProvinceCode);
        hm.put("pt_ResourceCode",pt_ResourceCode);
        String hmacKey = this.JSJ_KEY_NO;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_NO,hmacKey,hm, "POST", "gbk");
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            yeeBaoResult.setOrder(result.get("r4_Order")==null?"":result.get("r4_Order"));
            yeeBaoResult.setAmt(result.get("r3_Amt")==null?"":result.get("r3_Amt"));
            yeeBaoResult.setFee(result.get("rf_fee")==null?"":result.get("rf_fee"));
            yeeBaoResult.setCur(result.get("r4_Cur")==null?"":result.get("r4_Cur"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口退款异常");
        }
        return yeeBaoResult;
    }

    /**
     * 信用卡预授权消费
     * @return
     */
    public YeeBaoResult AuthSale(String jsjOrderId, BankCard bankCard, Customer customer, String callBackUrl)
    {
        String p0_Cmd = "EposLinkSale";//业务类型
        String p2_Order = jsjOrderId;//"test001";//商户订单号
        String p4_Cur = "CNY";//交易币种
        String p5_Pid = "flight";//商品名称
        String p8_Url = URL;//接收支付结果地址
        String pa_CredType = "IDCARD";//证件类型
        String pm_Period="3";//订单有效期
        String pn_Unit="day";//有效期单位
        String pa0_Mode="";//控制位
        String pa1_AuthorizeAmount="0.1";//预授权金额
        String pa5_BankBranch="beijing";//分行
        String pa6_CardType="VISA";//信用卡类型
        String pr_NeedResponse="1";//需要应答

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);////业务类型
        hm.put("p2_Order",p2_Order);//商户订单号
        hm.put("p4_Cur",p4_Cur);//交易币种
        hm.put("p5_Pid",p5_Pid);//商品名称
        hm.put("p8_Url",p8_Url);//接收支付结果地址
        hm.put("pa_CredType",pa_CredType);//证件类型
        hm.put("pb_CredCode",customer.getCustCertificateNo());//证件号码
        hm.put("pd_FrpId",bankCard.getCardNumber());//银行编码
        hm.put("pe_BuyerTel",customer.getContractPhoneOne());//消费者手机号
        hm.put("pf_BuyerName",customer.getCustomerName());//消费者姓名
        hm.put("pm_Period",pm_Period);//订单有效期
        hm.put("pn_Unit",pn_Unit);//有效期单位
        hm.put("pt_ActId",bankCard.getCardNumber());//信用卡卡号
        hm.put("pa0_Mode",pa0_Mode);//控制位
        hm.put("pa1_AuthorizeAmount",pa1_AuthorizeAmount);//预授权金额
        hm.put("pa2_ExpireYear",bankCard.getCreditCardTime().substring(0,3));//有效期（年）
        hm.put("pa3_ExpireMonth",bankCard.getCreditCardTime().substring(6,7));//有效期（月）
        hm.put("pa4_CVV",bankCard.getCvv2().toString());//CVV
        hm.put("pa5_BankBranch", pa5_BankBranch);//分行
        hm.put("pa6_CardType", pa6_CardType);//信用卡类型
        hm.put("pr_NeedResponse",pr_NeedResponse);//需要应答

        String hmacKey = this.JSJ_KEY;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE,hmacKey,hm, "POST", "gbk");
            //todo 该方法未调通
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口预授权消费异常");
        }
        return yeeBaoResult;
    }


    /**
     * 信用卡预授权确认
     * @param yeeBaoTrxId  易宝交易流水号
     * @param moneyAmout  预授权金额
     * @return
     */
    public YeeBaoResult AuthConConfirm(String yeeBaoTrxId, String moneyAmout)
    {
        String p0_Cmd = "EposConf";//业务类型
        String pb_TrxId = yeeBaoTrxId;//易宝支付交易流水号
        String p3_Amt=moneyAmout;//确认金额

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);////业务类型
        hm.put("pb_TrxId",pb_TrxId);//易宝支付交易流水号
        hm.put("p3_Amt",p3_Amt);//确认金额
        String hmacKey = this.JSJ_KEY;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE,hmacKey,hm, "POST", "gbk");
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            yeeBaoResult.setOrder(result.get("r6_Order")==null?"":result.get("r6_Order"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口预授权确认异常");
        }
        return yeeBaoResult;
    }

    /**
     * 信用卡预授权取消
     * @param yeeBaoTrxId 易宝交易流水号
     * @return
     */
    public YeeBaoResult AuthCancel(String yeeBaoTrxId)
    {
        String p0_Cmd = "EposCancel";//业务类型
        String pb_TrxId = yeeBaoTrxId;//易宝支付交易流水号

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);//业务类型
        hm.put("pb_TrxId",pb_TrxId);//易宝支付交易流水号
        String hmacKey = this.JSJ_KEY;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE,hmacKey,hm, "POST", "gbk");
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            yeeBaoResult.setOrder(result.get("r6_Order")==null?"":result.get("r6_Order"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口预授权取消异常");
        }
        return yeeBaoResult;
    }

    /**
     * 验证码确认消费
     */
    public YeeBaoResult VerifySale(String jsjOrderId, String verifyCode)
    {
        String p0_Cmd = "EposVerifySale";//业务类型:(固定值“EposVerifySale”)
        String p2_Order = jsjOrderId;//"test001";//商品订单号
        String pb_VerifyCode = verifyCode;//验证码

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);////业务类型
        hm.put("p2_Order",p2_Order);//商户订单号
        hm.put("pb_VerifyCode",pb_VerifyCode);//验证码
        String hmacKey = this.JSJ_KEY;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_YES,hmacKey,hm, "POST", "gbk");
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setErrorMsg(result.get("errorMsg")==null?"":result.get("errorMsg"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            yeeBaoResult.setOrder(result.get("r6_Order")==null?"":result.get("r6_Order"));
            yeeBaoResult.setBankOrderId(result.get("ro_BankOrderId")==null?"":result.get("ro_BankOrderId"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口验证码确认消费异常");
        }
        return yeeBaoResult;
    }

    /**
     * 订单验证码获取
     * @param jsjOrderId
     * @return
     */
    public YeeBaoResult VerifyCodeReceive(String jsjOrderId)
    {
        String p0_Cmd = "EposVerifyCodeReceive";//业务类型:(固定值“EposVerifyCodeReceive”)
        String p2_Order = jsjOrderId;//"test001";//商户订单号

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);////业务类型
        hm.put("p2_Order",p2_Order);//商户订单号
        String hmacKey = this.JSJ_KEY;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE_YES,hmacKey,hm, "POST", "gbk");
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setErrorMsg(result.get("errorMsg")==null?"":result.get("errorMsg"));
            yeeBaoResult.setMerId(result.get("p1_MerId")==null?"":result.get("p1_MerId"));
            yeeBaoResult.setOrder(result.get("r6_Order")==null?"":result.get("r6_Order"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口订单验证码获取异常");
        }
        return yeeBaoResult;
    }

    /**
     * 订单信息查询
     * @return
     */
    public YeeBaoResult QueryOrdDetail(String jsjOrderId)
    {
        String p0_Cmd = "QueryOrdDetail";//业务类型:(固定值” QueryOrdDetail”)
        String p2_Order = jsjOrderId;//"test001";//商户订单号
        String p3_ServiceType = "";//"test001";//查询类型:(不填或填固定值：0)

        Map<String,String> hm=new HashMap<String,String>();
        hm.put("p0_Cmd",p0_Cmd);////业务类型
        hm.put("p2_Order",p2_Order);//商户订单号
        hm.put("p3_ServiceType",p3_ServiceType);//查询类型
        String hmacKey = this.JSJ_KEY;//签名数据
        String eposReqUrl = Configuration.getInstance().getValue("eposReqUrl");
        YeeBaoResult yeeBaoResult = new YeeBaoResult();
        try {
            Map<String,String> result = null;
            result = EposFacade.trxRequest(eposReqUrl,this.JSJ_CODE,hmacKey,hm, "POST", "gbk");
            yeeBaoResult.setCmd(result.get("r0_Cmd")==null?"":result.get("r0_Cmd"));
            yeeBaoResult.setCode(result.get("r1_Code")==null?"":result.get("r1_Code"));
            yeeBaoResult.setTrxId(result.get("r2_TrxId")==null?"":result.get("r2_TrxId"));
            yeeBaoResult.setAmt(result.get("r3_Amt")==null?"":result.get("r3_Amt"));
            yeeBaoResult.setCur(result.get("r4_Cur")==null?"":result.get("r4_Cur"));
            yeeBaoResult.setPid(result.get("r5_Pid")==null?"":result.get("r5_Pid"));
            yeeBaoResult.setOrder(result.get("r6_Order")==null?"":result.get("r6_Order"));
            yeeBaoResult.setMP(result.get("r8_MP")==null?"":result.get("r8_MP"));
            yeeBaoResult.setRefundRequestID(result.get("rw_RefundRequestID")==null?"":result.get("rw_RefundRequestID"));
            yeeBaoResult.setCreateTime(result.get("rx_CreateTime")==null?"":result.get("rx_CreateTime"));
            yeeBaoResult.setFinshTime(result.get("ry_FinshTime")==null?"":result.get("ry_FinshTime"));
            yeeBaoResult.setRefundAmount(result.get("rz_RefundAmount")==null?"":result.get("rz_RefundAmount"));
            yeeBaoResult.setPayStatus(result.get("rb_PayStatus")==null?"":result.get("rb_PayStatus"));
            yeeBaoResult.setRefundCount(result.get("rc_RefundCount")==null?"":result.get("rc_RefundCount"));
            yeeBaoResult.setRefundAmt(result.get("rd_RefundAmt")==null?"":result.get("rd_RefundAmt"));
            yeeBaoResult.setHmac(result.get("hmac")==null?"":result.get("hmac"));
            yeeBaoResult.setAirAccount(result.get("airAccount")==null?"":result.get("airAccount"));
            yeeBaoResult.setAirOrderNo(result.get("airOrderNo")==null?"":result.get("airOrderNo"));
            return yeeBaoResult;
        } catch (Exception e) {
            e.printStackTrace();
            yeeBaoResult.setErrorMsg("易宝接口查询异常");
        }
        return yeeBaoResult;
    }

}
